import { createRouter, createWebHashHistory } from 'vue-router'
import Layout from '@/layout'

export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index.vue'),
    hidden: true
  },
  {
    path: '/404',
    component: () => import('@/views/error/404.vue'),
    hidden: true
  },
  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: 'Dashboard',
      component: () => import('@/views/dashboard/index.vue'),
      meta: { title: '首页', icon: 'Odometer' }
    }]
  },
  {
    path: '/venues',
    component: Layout,
    redirect: '/venues/list',
    name: 'Venues',
    meta: { title: '场馆管理', icon: 'OfficeBuilding' },
    children: [
      {
        path: 'list',
        name: 'VenueList',
        component: () => import('@/views/venue/list.vue'),
        meta: { title: '场馆列表' }
      },
      {
        path: 'edit/:id(\\d+)?',
        name: 'VenueEdit',
        component: () => import('@/views/venue/edit.vue'),
        meta: { title: '编辑场馆', noCache: true, activeMenu: '/venues/list' },
        hidden: true
      }
    ]
  },
  {
    path: '/activities',
    component: Layout,
    redirect: '/activities/list',
    name: 'Activities',
    meta: { title: '活动管理', icon: 'Calendar' },
    children: [
      {
        path: 'list',
        name: 'ActivityList',
        component: () => import('@/views/activity/list.vue'),
        meta: { title: '活动列表' }
      },
      {
        path: 'detail/:id',
        name: 'ActivityDetail',
        component: () => import('@/views/activity/detail.vue'),
        meta: { title: '活动详情', hidden: true, activeMenu: '/activities/list' }
      }
    ]
  },
  {
    path: '/banners',
    component: Layout,
    children: [
      {
        path: 'list',
        name: 'BannerList',
        component: () => import('@/views/banner/BannerList.vue'),
        meta: { title: '轮播图管理', icon: 'PictureFilled' }
      }
    ]
  },
  {
    path: '/users',
    component: Layout,
    children: [
      {
        path: 'list',
        name: 'UserList',
        component: () => import('@/views/user/UserList.vue'),
        meta: { title: '用户管理', icon: 'UserFilled' }
      }
    ]
  },
  {
    path: '/orders',
    component: Layout,
    redirect: '/orders/list',
    name: 'Orders',
    meta: { title: '订单管理', icon: 'ShoppingCartFull' },
    children: [
      {
        path: 'list',
        name: 'OrderList',
        component: () => import('@/views/order/list.vue'),
        meta: { title: '订单列表' }
      },
      {
        path: 'statistics',
        name: 'OrderStatistics',
        component: () => import('@/views/order/statistics.vue'),
        meta: { title: '订单统计' }
      }
    ]
  },
  {
    path: '/payment',
    component: Layout,
    redirect: '/payment/list',
    name: 'Payment',
    meta: { title: '支付管理', icon: 'CreditCard' },
    children: [
      {
        path: 'list',
        name: 'PaymentList',
        component: () => import('@/views/payment/list.vue'),
        meta: { title: '支付记录' }
      },
      {
        path: 'settings',
        name: 'PaymentSettings',
        component: () => import('@/views/payment/settings.vue'),
        meta: { title: '支付设置' }
      }
    ]
  },
  {
    path: '/devices',
    component: Layout,
    children: [
      {
        path: 'list',
        name: 'DeviceList',
        component: () => import('@/views/device/list.vue'),
        meta: { title: '设备管理', icon: 'Monitor' }
      }
    ]
  },
  {
    path: '/system',
    component: Layout,
    redirect: '/system/admin',
    name: 'System',
    meta: { title: '系统管理', icon: 'Setting' },
    children: [
      {
        path: 'admin',
        name: 'SystemAdmin',
        component: () => import('@/views/system/admin.vue'),
        meta: { title: '管理员管理' }
      },
      {
        path: 'role',
        name: 'SystemRole',
        component: () => import('@/views/system/role.vue'),
        meta: { title: '角色管理' }
      },
      {
        path: 'log',
        name: 'SystemLog',
        component: () => import('@/views/system/log.vue'),
        meta: { title: '系统日志' }
      }
    ]
  },
  // 404 page must be placed at the end !!!
  { path: '/:catchAll(.*)', redirect: '/404', hidden: true }
]

const router = createRouter({
  history: createWebHashHistory(),
  scrollBehavior: () => ({ top: 0 }),
  routes: constantRoutes
})

export default router
